import {
    msg
} from '../common/layer';

const upFile = () => {
    var ie = !-[1,];
    if(ie){
        $('input:file').trigger('click').trigger('change');
    }else{
        $('input:file').trigger('click');
    }
    $('input:file').change(function(){
        startUploading();
    });
};
const startUploading = () => {
    var oMyForm = new FormData();
    var file = document.getElementById('fileupload').files[0];

    // fileInputElement中已经包含了用户所选择的文件
    if (file) {
        oMyForm.append("attach", file);

        $.ajax({
            url: GLOBAL_fileUrl,
            type: 'POST',
            data: oMyForm,
            // 告诉jQuery不要去处理发送的数据
            processData: false,
            // 告诉jQuery不要去设置Content-Type请求头
            contentType: false,
            success: function (res) {
                msg(res.msg);
                $("#content").val(res.path);
                $("#linkUrl").text(res.path);
            }
        });
    }
}
export {
    upFile
}